{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9e4d4a4b",
   "metadata": {},
   "outputs": [],
   "source": [
    "from gs_quant.session import Environment, GsSession\n",
    "from gs_quant.markets.index import Index"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3027d017",
   "metadata": {},
   "source": [
    "## Pre Requisites\n",
    "To use below functionality on **STS Indices**, your application needs to have access to the following datasets:\n",
    "4. [STS_UNDERLIER_WEIGHTS](https://marquee.gs.com/s/developer/datasets/STS_UNDERLIER_WEIGHTS) - Weights of index underliers of STS Indices\n",
    "5. [STS_UNDERLIER_ATTRIBUTION](https://marquee.gs.com/s/developer/datasets/STS_UNDERLIER_ATTRIBUTION) - Attribution of index underliers\n",
    "\n",
    "You can request access by going to the Dataset Catalog Page linked above.\n",
    "\n",
    "Note - Please skip this if you are an internal user"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f6a8d144",
   "metadata": {},
   "outputs": [],
   "source": [
    "# external users should substitute their client id and secret; please skip this step if using internal jupyterhub\n",
    "GsSession.use(Environment.PROD, client_id=None, client_secret=None, scopes=('read_product_data',))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "827dc4fc",
   "metadata": {},
   "outputs": [],
   "source": [
    "strategy_index = Index.get('GSXXXXXX')  # substitute input with any identifier for an index"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f88343e4",
   "metadata": {},
   "source": [
    "### These functions currently supports STS indices only"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d39c29b5",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Returns a pandas dataframe containing latest weights of the immediate underliers of the index\n",
    "strategy_index.get_underlier_weights()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b3758a0e",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Returns a pandas dataframe containing latest attribution of the immediate underliers of the index\n",
    "strategy_index.get_underlier_attribution()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ae9d3263",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Get the latest weights and attribution of the underliers at all levels\n",
    "strategy_index.get_underlier_tree().to_frame()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6994f631",
   "metadata": {},
   "source": [
    "*Have any other questions? Reach out to the [Marquee STS team](mailto:gs-marquee-sts-support@gs.com)!*"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
